package com.ruoyi.zyx.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxTakecare;
import com.ruoyi.zyx.service.IZyxTakecareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保养信息Controller
 *
 * @author lhs
 * @date 2021-06-01
 */
@RestController
@RequestMapping("/zyx/takecare")
public class ZyxTakecareController extends BaseController
{
    @Autowired
    private IZyxTakecareService zyxTakecareService;

    /**
     * 查询保养信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:takecare:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyxTakecare zyxTakecare)
    {
        startPage();
        List<ZyxTakecare> list = zyxTakecareService.selectZyxTakecareList(zyxTakecare);
        return getDataTable(list);
    }
    @GetMapping("/listMyTakecare")
    public TableDataInfo listMyTakecare(ZyxTakecare zyxTakecare)
    {
        startPage();
        zyxTakecare.setDepartid(SecurityUtils.getLoginUser().getUser().getDeptId());
        List<ZyxTakecare> list = zyxTakecareService.listMyTakecare(zyxTakecare);
        return getDataTable(list);
    }

    /**
     * 导出保养信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:takecare:export')")
    @Log(title = "保养信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxTakecare zyxTakecare)
    {
        List<ZyxTakecare> list = zyxTakecareService.selectZyxTakecareList(zyxTakecare);
        ExcelUtil<ZyxTakecare> util = new ExcelUtil<ZyxTakecare>(ZyxTakecare.class);
        return util.exportExcel(list, "保养信息数据");
    }

    /**
     * 获取保养信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:takecare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxTakecareService.selectZyxTakecareById(id));
    }

    /**
     * 新增保养信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:takecare:add')")
    @Log(title = "保养信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxTakecare zyxTakecare)
    {
        return toAjax(zyxTakecareService.insertZyxTakecare(zyxTakecare));
    }

    /**
     * 修改保养信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:takecare:edit')")
    @Log(title = "保养信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxTakecare zyxTakecare)
    {
        zyxTakecare.setIswarn("N");
        return toAjax(zyxTakecareService.updateZyxTakecare(zyxTakecare));
    }

    /**
     * 删除保养信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:takecare:remove')")
    @Log(title = "保养信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxTakecareService.deleteZyxTakecareByIds(ids));
    }
}
